const app = getApp()
const api = require('../../../../config/api.js')
Page({
  data: {
    aboutMe:"",
    hobby:"",
    sentimentView:"",
    loveTa:""
  },

  onLoad() {
    this.setData({
      menuPos:app.globalData.menuPos,
      phoneInfo:app.globalData.phoneInfo,
      aboutMe:app.globalData.xuserInfo.aboutMe ? app.globalData.xuserInfo.aboutMe : "",
      hobby:app.globalData.xuserInfo.hobby ? app.globalData.xuserInfo.hobby : "",
      sentimentView:app.globalData.xuserInfo.sentimentView ? app.globalData.xuserInfo.sentimentView : "",
      loveTa:app.globalData.xuserInfo.loveTa ? app.globalData.xuserInfo.loveTa : "",
    })
  },
  onUnload:function(){
    qq.navigateTo({
      url: "/pages/mine/profile/profile"
    })
  },

  getAboutMe:function(e){
    let aboutMe = e.detail.value
    this.setData({
      aboutMe:aboutMe
    })
  },
  getHobby:function(e){
    let hobby = e.detail.value
    this.setData({
      hobby:hobby
    })
  },
  getSentimentView:function(e){
    let sentimentView = e.detail.value
    console.log(aboutMe)
    this.setData({
      sentimentView:sentimentView
    })
  },
  getLoveTa:function(e){
    let loveTa = e.detail.value
    console.log(aboutMe)
    this.setData({
      loveTa:loveTa
    })
  },
  saveFile:function(){
    let aboutMe = this.data.aboutMe
    let hobby = this.data.hobby
    let sentimentView = this.data.sentimentView
    let loveTa = this.data.loveTa
    app.globalData.xuserInfo.aboutMe = aboutMe
    app.globalData.xuserInfo.hobby = hobby
    app.globalData.xuserInfo.sentimentView = sentimentView
    app.globalData.xuserInfo.loveTa = loveTa
    qq.request({
      url: api.SyncXUserInfo,
      data: {"xuserInfo":app.globalData.xuserInfo},
      header: {
          'Content-Type': 'application/json',
          'Xworld-Token': app.globalData.token
      },
      method: 'POST',
      success: res => {
          app.globalData.xuserInfo = res.data.data.xuserInfo
          console.log('res success qq.getXUserInfo', res)
      },  
      fail: res => {
          console.log('res fail', res)
      }
    })
    qq.navigateTo({
      url: '/pages/mine/profile/profile'　　
    })
  }

})

